/*
 * Created by JFormDesigner on Mon Jul 01 20:01:21 CST 2024
 */

package scct.ZhuZhouXing.ui;

import scct.ZhuZhouXing.dao.MembersDao;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * @author xzy
 */
public class DlgMembersAdd extends JDialog {
    public DlgMembersAdd(Window owner) {
        super(owner);
        initComponents();
        initView();
    }

    private void initView() {

    }
    private void btnAdd(ActionEvent e) {
        String name = txtName.getText();
        String sex = radFemale.getText();
        String account = txtAccount.getText();
        String password = txtPass.getText();
        String member = (String) comleibie.getSelectedItem();
        String number = txtNumber.getText();

        if (name.isEmpty()||name.length()>10) {
            JOptionPane.showMessageDialog(this, "请输入合法的名字");
            return;
        }
        if (account.isEmpty()||account.length()>10) {
            JOptionPane.showMessageDialog(this, "请输入合法的账号");
            return;
        }
        if (password.isEmpty()||password.length()>10) {
            JOptionPane.showMessageDialog(this, "请输入合法密码");
            return;
        }
        if (member.isEmpty()||member.length()>10) {
            JOptionPane.showMessageDialog(this, "请输入合法类型");
            return;
        }
        if (number.isEmpty()||number.length()>11) {
            JOptionPane.showMessageDialog(this, "请输入合法手机号");
            return;
        }
        MembersDao membersDao = new MembersDao();
        if (membersDao.addMembers(name, sex,account, password, member, number)) {
            JOptionPane.showMessageDialog(this, "添加成功！");
            PaneMembersManager.getTable();
            this.dispose();
        } else {
            JOptionPane.showMessageDialog(this, "添加失败！");
        }
    }
    private void btncnel(ActionEvent e) {
        this.dispose();
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        // Generated using JFormDesigner Evaluation license - 周文成
        label1 = new JLabel();
        label2 = new JLabel();
        label3 = new JLabel();
        label4 = new JLabel();
        txtName = new JTextField();
        label6 = new JLabel();
        btnAdd = new JButton();
        btnCancel = new JButton();
        comleibie = new JComboBox<>();
        txtAccount = new JTextField();
        txtPass = new JTextField();
        label5 = new JLabel();
        txtNumber = new JTextField();
        label7 = new JLabel();
        radMale = new JRadioButton();
        radFemale = new JRadioButton();

        //======== this ========
        setTitle("\u4f1a\u5458\u6dfb\u52a0");
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- label1 ----
        label1.setText("\u4f1a\u5458\u59d3\u540d");
        label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 2f));
        contentPane.add(label1);
        label1.setBounds(100, 70, 71, 30);

        //---- label2 ----
        label2.setText("\u8d26\u6237");
        label2.setFont(label2.getFont().deriveFont(label2.getFont().getSize() + 2f));
        contentPane.add(label2);
        label2.setBounds(100, 185, 71, 30);

        //---- label3 ----
        label3.setText("\u5bc6\u7801");
        label3.setFont(label3.getFont().deriveFont(label3.getFont().getSize() + 2f));
        contentPane.add(label3);
        label3.setBounds(100, 215, 71, 30);

        //---- label4 ----
        label4.setText("\u4f1a\u5458\u7c7b\u522b");
        label4.setFont(label4.getFont().deriveFont(label4.getFont().getSize() + 2f));
        contentPane.add(label4);
        label4.setBounds(100, 270, 71, 30);
        contentPane.add(txtName);
        txtName.setBounds(185, 70, 220, 30);

        //---- label6 ----
        label6.setText("\u4f1a\u5458\u6dfb\u52a0");
        label6.setFont(label6.getFont().deriveFont(label6.getFont().getSize() + 14f));
        contentPane.add(label6);
        label6.setBounds(230, -5, 145, 65);

        //---- btnAdd ----
        btnAdd.setText("\u6dfb\u52a0");
        btnAdd.addActionListener(e -> btnAdd(e));
        contentPane.add(btnAdd);
        btnAdd.setBounds(160, 435, 85, 40);

        //---- btnCancel ----
        btnCancel.setText("\u53d6\u6d88");
        btnCancel.addActionListener(e -> btncnel(e));
        contentPane.add(btnCancel);
        btnCancel.setBounds(315, 430, 85, 40);

        //---- comleibie ----
        comleibie.setModel(new DefaultComboBoxModel<>(new String[] {
            "\u521d\u7ea7\u4f1a\u5458",
            "\u6807\u51c6\u4f1a\u5458",
            "\u767d\u91d1\u4f1a\u5458",
            "\u94bb\u77f3\u4f1a\u5458",
            "\u7cbe\u82f1\u4f1a\u5458",
            "\u8363\u8a89\u4f1a\u5458",
            "\u81f3\u5c0a\u4f1a\u5458",
            "\u4f20\u5947\u4f1a\u5458"
        }));
        contentPane.add(comleibie);
        comleibie.setBounds(185, 265, 220, 40);
        contentPane.add(txtAccount);
        txtAccount.setBounds(185, 185, 220, txtAccount.getPreferredSize().height);
        contentPane.add(txtPass);
        txtPass.setBounds(185, 225, 220, txtPass.getPreferredSize().height);

        //---- label5 ----
        label5.setText("\u624b\u673a\u53f7\u7801");
        label5.setFont(label5.getFont().deriveFont(label5.getFont().getSize() + 2f));
        contentPane.add(label5);
        label5.setBounds(100, 335, 71, 30);
        contentPane.add(txtNumber);
        txtNumber.setBounds(185, 335, 220, txtNumber.getPreferredSize().height);

        //---- label7 ----
        label7.setText("\u6027\u522b");
        label7.setFont(label7.getFont().deriveFont(label7.getFont().getSize() + 2f));
        contentPane.add(label7);
        label7.setBounds(100, 125, 71, 30);

        //---- radMale ----
        radMale.setText("\u7537");
        contentPane.add(radMale);
        radMale.setBounds(new Rectangle(new Point(185, 130), radMale.getPreferredSize()));

        //---- radFemale ----
        radFemale.setText("\u5973");
        contentPane.add(radFemale);
        radFemale.setBounds(new Rectangle(new Point(300, 130), radFemale.getPreferredSize()));

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        setSize(595, 575);
        setLocationRelativeTo(getOwner());

        //---- buttonGroup1 ----
        ButtonGroup buttonGroup1 = new ButtonGroup();
        buttonGroup1.add(radMale);
        buttonGroup1.add(radFemale);
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    // Generated using JFormDesigner Evaluation license - 周文成
    private JLabel label1;
    private JLabel label2;
    private JLabel label3;
    private JLabel label4;
    private JTextField txtName;
    private JLabel label6;
    private JButton btnAdd;
    private JButton btnCancel;
    private JComboBox<String> comleibie;
    private JTextField txtAccount;
    private JTextField txtPass;
    private JLabel label5;
    private JTextField txtNumber;
    private JLabel label7;
    private JRadioButton radMale;
    private JRadioButton radFemale;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
